package com.lj.sys.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.lj.common_web.annotation.ResponseResultVo;
import com.lj.sys.param.SysConfigPageParam;
import com.lj.sys.param.SysConfigSaveParam;
import com.lj.sys.param.SysConfigUpdateParam;
import com.lj.sys.result.SysConfigInfoResult;
import com.lj.sys.result.SysConfigPageResult;
import com.lj.sys.service.SysConfigService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 系统配置表 前端控制器
 * </p>
 *
 * @author luojing
 * @since 2025-02-21 14:05:11
 */
@RestController
@RequestMapping("/sys/sys_config")
@ResponseResultVo
@Tag(name = "系统配置表 管理")
public class SysConfigController {

    @Resource
    private SysConfigService sysConfigService;

    @GetMapping("/page")
    @SaCheckPermission("sys:sys_config:list")
    @Operation(summary = "系统配置表 分页查询")
    public IPage<SysConfigPageResult> page(@ParameterObject SysConfigPageParam param) {
        return sysConfigService.page(param);
    }

    @GetMapping("/info/{id}")
    @SaCheckPermission("sys:sys_config:info")
    @Operation(summary = "系统配置表 信息")
    public SysConfigInfoResult info(@PathVariable("id") @Parameter(name = "id", description = "系统配置表 id") Long id) {
        if (id == null) {
            return null;
        }
        return sysConfigService.info(id);
    }

    @GetMapping("/config/{configKey}")
    @Operation(summary = "通过配置key获取配置value")
    public String getConfigValueByKey(@PathVariable("configKey")
                                      @Parameter(name = "configKey", description = "配置key") String configKey) {
        return sysConfigService.getValue(configKey);
    }

    @PostMapping("/save")
    @SaCheckPermission("sys:sys_config:save")
    @Operation(summary = "系统配置表 新增")
    public void save(@RequestBody @Validated SysConfigSaveParam param) {
        sysConfigService.save(param);
    }

    @PostMapping("/update")
    @SaCheckPermission("sys:sys_config:update")
    @Operation(summary = "系统配置表 更新")
    public void update(@RequestBody @Validated SysConfigUpdateParam param) {
        sysConfigService.update(param);
    }

    @PostMapping("/delete")
    @SaCheckPermission("sys:sys_config:delete")
    @Operation(summary = "系统配置表 删除")
    public void delete(@RequestBody List<Long> ids) {
        sysConfigService.delete(ids);
    }

}

